import { QuestionCircleFilled } from "@ant-design/icons"
import { Flex, Tooltip } from "antd"
import { useSelector } from "react-redux"
import { Link } from "react-router-dom"

import { useDataMapping, useDigital, useLocale } from "@/hooks"
import { BetType } from "@/interface/store/config"
import { AppState } from "@/stores"

export type RecordType = {
	id: string
	generatedId: string
	venueTypeCode: string
	venueCode: string
	gameTypeId: string
	gameTypeName: string
	parentProxyId: string
	parentProxyName: string
	topProxyId: string
	topProxyName: string
	memberName: string
	playerName: string
	accountType: number
	obDeviceType: number
	vipLevel?: any
	vipRebateRate?: any
	rebateAmount?: any
	loginIp: string
	merchantId: string
	merchantName: string
	betAmount: number
	validBetAmount: number
	netAmount: number
	payAmount?: any
	obBetStatus: number
	createAt: string
	netAt: string
	matchInfo: string
	matchId?: any
	betContent: string
	memberCurrency: string
	createAtString: string
	netAtString: string
	venueTypeName: string
	venueName: string
	betType: number
	parentBetType: number
	pumpContribution: number
	obSettleCount?: any
	betOrderId?: any
	businessModel: number
	memberId: string
	roundNo: string
	tableId: string
	bbBlindScore: string
	sbBlindScore: string
	ipAttribution: string
	pumpingAmount?: any
	roundId?: any
	bootNo?: any
	userHandFee: number
}
export interface RootObject {
	id: string
	generatedId: string
	playerName: string
	clubId: number
	tableId: string
	tableCode: string
	tableName: string
	gameName: string
	handId: string
	betAmount: number
	validBetAmount: number
	netAmount: number
	loginIp: string
	handBeginDate: string
	obDeviceType: number
	obBetStatus: number
	handEndDate: string
	venueTypeCode: string
	gameType: number
	memberCurrency: string
	betType: number
	betTypeDesc: string
	parentOrderType: number
	parentOrderTypeDesc: string
	pumpContribution: number
	memberId: string
	handInfo: string
	nickName: string
	resultInfo: string
	globalPokerCode: string
	showStatus: number
	totalNetAmount: number
	loseCards: string
	extendProperty: string
	grossProfit: number
	userHandFee: number
}
const betSlipColumns = () => {
	const { newFormat, formatMessage } = useLocale()
	const { renderCopyNo, renderColor, renderFormat, renderButton, renderSlash } = useDigital()
	const { getFromDic } = useDataMapping()
	const { betTypes } = useSelector((state: AppState) => state.config)
	const renderBetType = (bt: BetType[]) => (text: number, record: RecordType) => {
		let target = bt.find(p => p.type === record.parentBetType)?.subList?.find(c => c.type === text)?.desc ?? "-"
		if (target === "手牌服务费") target = "俱乐部游戏"
		return target
	}
	const clubId = {
		dataIndex: "clubId",
		title: newFormat("label.clubId"),
		width: 120,
		align: "center",
		render: (clubId: string) => <Link to={`/dxn/clubManager/clubList?clubId=${clubId}`}>{clubId}</Link>
	}
	const tableId = {
		dataIndex: "tableId",
		title: newFormat("label.tableId"),
		width: 120,
		align: "center",
		render: renderButton(() => {}, true)
	}
	const tableName = {
		dataIndex: "tableName",
		title: newFormat("label.tableName"),
		width: 120,
		align: "center"
	}
	const betId = {
		dataIndex: "id",
		title: newFormat("label.bet.id"),
		align: "center",
		width: 220
	}
	const betType = {
		dataIndex: "betType",
		title: newFormat("label.bet.parentBetType"),
		width: 120,
		align: "center",
		render: renderBetType(betTypes)
	}
	const userHandFee = {
		dataIndex: "userHandFee",
		title: newFormat("label.bet.userHandFee"),
		titleText: formatMessage({ id: "label.bet.userHandFee" }),
		width: 120,
		align: "center",
		render: (text: number, record: RecordType) => (!record?.betType || record.betType === 1 ? renderFormat(text) : "-")
	}
	const betMember = {
		dataIndex: "memberName",
		title: newFormat("label.memberName"),
		align: "center",
		width: 200,
		render: renderCopyNo
	}
	const generateId = {
		dataIndex: "generatedId",
		title: newFormat("label.thirdBetId"),
		align: "center",
		width: 200
	}
	const venueTypeName = {
		dataIndex: "venueTypeName",
		title: newFormat("label.venueType"),
		align: "center",
		width: 120
	}
	const venueName = {
		dataIndex: "venueName",
		title: newFormat("label.venueName"),
		align: "center",
		width: 120
	}
	const gameTypeName = {
		dataIndex: "gameTypeName",
		title: newFormat("label.gameName"),
		align: "center",
		width: 120
	}
	const dxnGameName = {
		dataIndex: "gameType",
		title: newFormat("label.gameName"),
		align: "center",
		width: 120,
		render: getFromDic("gameType", false)
	}
	const playerName = {
		dataIndex: "playerName",
		title: newFormat("label.playerName"),
		align: "center",
		width: 150,
		render: renderCopyNo
	}
	const accountType = {
		dataIndex: "accountType",
		title: newFormat("label.accountType"),
		align: "center",
		width: 120,
		render: getFromDic("accountType", false)
	}
	const parentBetType = {
		dataIndex: "parentBetType",
		title: newFormat("label.parentBetType"),
		align: "center",
		width: 120,
		render: (text: number) => {
			return text === 101 ? "俱乐部服务费" : text === 102 ? "保险" : "-"
		}
	}
	const parentBetTypeDesc = {
		dataIndex: "parentOrderTypeDesc",
		title: newFormat("label.parentBetType"),
		align: "center",
		width: 120
	}
	const betTypeDesc = {
		dataIndex: "betTypeDesc",
		title: newFormat("label.bet.betType"),
		align: "center",
		width: 120
	}
	const pumpContribution = {
		dataIndex: "pumpContribution",
		title: newFormat("label.pumpContribution"),
		align: "center",
		width: 160,
		render: renderFormat
	}
	const dxnPumpContribution = {
		dataIndex: "pumpContribution",
		title: newFormat("label.dxnPumpContribution"),
		align: "center",
		width: 160,
		render: renderFormat
	}
	const memberWin = {
		dataIndex: "netAmount",
		title: newFormat("label.memberWin"),
		titleText: newFormat("label.memberWin"),
		align: "center",
		width: 120,
		render: renderColor
	}
	const memberWinBefore = {
		dataIndex: "grossProfit",
		title: newFormat("label.memberWinBefore"),
		align: "center",
		width: 120,
		render: (text: number, record: RecordType) => (!record?.betType || record.betType === 1 ? renderColor(text) : "-")
	}
	const memberWinAfter = {
		dataIndex: "netAmount",
		title: newFormat("label.memberWinAfter"),
		align: "center",
		width: 120,
		render: renderColor
	}
	const dxnProfit = {
		dataIndex: "netAmount",
		title: (
			<Flex vertical={false}>
				{newFormat("label.memberWinAfter")}
				<Tooltip placement="top" title={newFormat("dxn.card_ables_list.profit_after_service")}>
					<QuestionCircleFilled style={{ marginLeft: 5 }} />
				</Tooltip>
			</Flex>
		),
		align: "center",
		width: 120,
		render: renderColor
	}
	const betStatus = {
		dataIndex: "obBetStatus",
		title: newFormat("label.bet.status"),
		align: "center",
		width: 120,
		render: getFromDic("betStatusType", false)
	}
	const settleStatus = {
		dataIndex: "obSettleCount",
		title: newFormat("label.isReSettle"),
		align: "center",
		width: 120,
		render: (text: number, record: RecordType) => {
			return record.obBetStatus === 0
				? "-"
				: [
						{ label: newFormat("label.reSettle.0"), value: 0 },
						{ label: newFormat("label.reSettle.1"), value: 1 },
						{ label: newFormat("label.reSettle.2"), value: 2 },
						{ label: newFormat("label.reSettle.3"), value: 3 }
				  ][!text ? 0 : text < 4 ? text : 3].label
		}
	}
	const resettleStatus = {
		dataIndex: "obSettleCount",
		title: newFormat("label.isReSettle"),
		align: "center",
		width: 120,
		render: (text: number, record: RecordType) => {
			return record.obBetStatus !== 1 ? (
				"-"
			) : (
				<span style={{ color: "red" }}>
					{
						[
							{ label: "-", value: 0 },
							{ label: newFormat("label.reSettle.1"), value: 1 },
							{ label: newFormat("label.reSettle.2"), value: 2 },
							{ label: newFormat("label.reSettle.3"), value: 3 }
						][!text ? 0 : text < 4 ? text : 3].label
					}
				</span>
			)
		}
	}
	const renderTime = (dataIndex: string) => {
		return {
			dataIndex,
			title: newFormat(`label.${dataIndex}`),
			align: "center",
			width: 200
		}
	}
	const betCreate = renderTime("createAtString")
	const betBegin = {
		dataIndex: "handBeginDate",
		title: newFormat(`label.bet.createAt`),
		align: "center",
		width: 200
	}
	const betEnd = {
		dataIndex: "handEndDate",
		title: newFormat(`label.bet.checkAt`),
		align: "center",
		width: 200
	}
	const betCheck = renderTime("netAtString")
	const matchInfo = {
		dataIndex: "matchInfo",
		title: newFormat("label.matchInfo"),
		align: "center",
		width: 200
	}
	const betContent = {
		dataIndex: "betContent",
		title: newFormat("label.betContent"),
		align: "center",
		width: 200
	}
	const loginIp = {
		dataIndex: "loginIp",
		title: newFormat("label.loginIp"),
		align: "center",
		width: 120
	}
	const betIp = {
		dataIndex: "loginIp",
		title: newFormat("label.betIp"),
		align: "center",
		width: 120
	}
	const ipLocation = {
		dataIndex: "ipAttribution",
		title: newFormat("label.ipAttribution"),
		align: "center",
		width: 200,
		render: (text: string) => {
			return text || "-"
		}
	}
	const gameDeviceType = {
		dataIndex: "obDeviceType",
		title: newFormat("label.bet.betDevice"),
		width: 120,
		align: "center",
		render: getFromDic("login_device_type1", false)
	}
	const resetTime = {
		dataIndex: "obCreatedAt",
		title: newFormat(`label.bet.resetTime`),
		align: "center",
		width: 200,
		render: renderSlash
	}
	const resetTimes = {
		dataIndex: "obSettleCount",
		title: newFormat(`label.bet.resetTimes`),
		align: "center",
		width: 120,
		render: renderSlash
	}
	return {
		betId,
		betMember,
		generateId,
		venueTypeName,
		venueName,
		gameTypeName,
		playerName,
		accountType,
		parentBetType,
		pumpContribution,
		dxnPumpContribution,
		memberWin,
		memberWinBefore,
		memberWinAfter,
		betStatus,
		settleStatus,
		betCreate,
		betCheck,
		matchInfo,
		betContent,
		ipLocation,
		clubId,
		tableId,
		tableName,
		parentBetTypeDesc,
		betTypeDesc,
		betType,
		userHandFee,
		betBegin,
		betEnd,
		gameDeviceType,
		loginIp,
		betIp,
		dxnGameName,
		dxnProfit,
		resetTime,
		resetTimes,
		resettleStatus
	}
}
export default betSlipColumns
